const ExcelJS = require('exceljs');
// const translations = require('./WT02/H5Ctrl_en.json');
// const translations = require('./WT02/H5Ctrl_de.json');
// const translations = require('./WT02/H5Ctrl_fr.json');
const en_Json = require('./h5Ctrlnew_en.json');
const de_Json = require('./h5Ctrlnew_de.json');
const fr_Json = require('./h5Ctrlnew_fr.json');

const soursArr = [
  {exportName: 'translations_en', targetJson: en_Json},
  {exportName: 'translations_de', targetJson: de_Json},
  {exportName: 'translations_fr', targetJson: fr_Json},
]

soursArr.forEach((item) => {
  // 创建一个新的Excel工作簿
  const workbook = new ExcelJS.Workbook();
  const worksheet = workbook.addWorksheet('Translations');

// 将多语言条目写入Excel工作表
  Object.entries(item.targetJson).forEach(([key, value], index) => {
    worksheet.getCell(`A${index + 1}`).value = key;
    worksheet.getCell(`B${index + 1}`).value = value;
  });

// 保存Excel文件
  workbook.xlsx.writeFile(`${item.exportName}.xlsx`)
      .then(() => {
        console.log(`${item.exportName}.xlsx 文件已创建`);
      })
      .catch((error) => {
        console.error('保存Excel文件时出错:', error);
      });
})
